<?php
namespace Framework\DiServices;

use Phalcon\Events\Event;
use Phalcon\Events\Manager as EventsManager;

/**
 * 主要针对mvc
 */
class View extends \Phalcon\Mvc\View
{
    public function __construct($viewsDir, $options = null)
    {
        parent::__construct($options);
        $this->setViewsDir($viewsDir); // 布局文件目录
        $this->setLayoutsDir('layouts/');     // 定义布局文件目录
        $this->setLayout('main');// 主布局文件

        $eventsManager = new EventsManager();
        // 支持前端debug数据
        if (!empty($_GET['__debug'])) {
            $eventsManager->attach(
                'view:afterRender',
                function (Event $event, $view) {
                    echo "<div><br /> <h3> debug渲染数据为：</h3><div>" .json_encode($this->getParamsToView())."</div></div>";
                    die;
                }
            );
            $this->setEventsManager($eventsManager);
        }
    }
}
